package com.example.conventor;

import com.example.constant.UserStatus2;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 序列化  jeff
 * @since 2023/5/1 11:46
 */
public class UserStatusEnumSerializer extends JsonSerializer<UserStatus2> {

    @Override
    public void serialize(UserStatus2 status, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        System.out.println("正在执行方法");
//        jsonGenerator.writeNumber(status.getValue());
        jsonGenerator.writeStartObject();
        jsonGenerator.writeFieldName("name");
        jsonGenerator.writeString(status.getDesc());
        jsonGenerator.writeFieldName("code");
        jsonGenerator.writeNumber(status.getValue());
        jsonGenerator.writeEndObject();
        System.out.println("json写入完成");

    }
}

